package pzk.page.renderer;

import java.io.IOException;
import java.io.Writer;
import java.util.Date;

import javax.servlet.http.HttpServletResponse;

import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
import org.zkoss.zk.ui.sys.PageRenderer;

import com.itextpdf.text.Document;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.PdfWriter;

public class PZKPageRenderer implements PageRenderer {

	@Override
	public void render(Page page, Writer out) throws IOException {
		try {
			// step 1
			Document document = new Document();
			// step 2
			HttpServletResponse response = (HttpServletResponse) Executions
					.getCurrent().getNativeResponse();
			
			PdfWriter.getInstance(document, response.getOutputStream());
			// step 3
			document.open();
			// step 4
			document.add(new Paragraph("Hello World"));
			document.add(new Paragraph(new Date().toString()));
			// step 5
			document.close();

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
